package com.fishery.refrigeratory.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fishery.refrigeratory.entity.RefrigeratoryAccessInfo;
import com.fishery.refrigeratory.mapper.RefrigeratoryAccessInfoMapper;
import com.fishery.refrigeratory.service.RefrigeratoryAccessInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RefrigeratoryAccessInfoServiceImpl extends ServiceImpl<RefrigeratoryAccessInfoMapper, RefrigeratoryAccessInfo>
        implements RefrigeratoryAccessInfoService {

    @Autowired
    private RefrigeratoryAccessInfoMapper refrigeratoryAccessInfoMapper;

    /**
     * 增加出入库信息
     * @author wgz
     * @since 2021/1/23
     * @param refrigeratoryAccessInfo
     */
    @Override
    public Integer createRefrigeratoryAccessInfo(RefrigeratoryAccessInfo refrigeratoryAccessInfo) {
        return refrigeratoryAccessInfoMapper.insert(refrigeratoryAccessInfo);
    }

    /**
     * 更改出入库信息
     * @author wgz
     * @since 2021/1/23
     * @param refrigeratoryAccessInfo
     */
    @Override
    public Integer updateRefrigeratoryAccessInfo(RefrigeratoryAccessInfo refrigeratoryAccessInfo) {
        return refrigeratoryAccessInfoMapper.updateById(refrigeratoryAccessInfo);
    }

    /**
     * 删除出入库信息
     * @author wgz
     * @since 2021/1/23
     * @param id
     */
    @Override
    public Integer deleteRefrigeratoryAccessInfo(String id) {
        return refrigeratoryAccessInfoMapper.deleteById(id);
    }

    /**
     * 通过id得到出入库信息
     * @author wgz
     * @since 2021/1/23
     * @param id
     */
    @Override
    public List<RefrigeratoryAccessInfo> getRefrigeratoryAccessInfoById(String id) {
        QueryWrapper<RefrigeratoryAccessInfo> wrapper = new QueryWrapper<RefrigeratoryAccessInfo>();
        wrapper.eq("id", id);
        return refrigeratoryAccessInfoMapper.selectList(wrapper);
    }

    /**
     * 获得所有的出入库信息
     * @return
     */
    @Override
    public List<RefrigeratoryAccessInfo> getAllRefrigeratoryAccessInfo() {
        return refrigeratoryAccessInfoMapper.selectList(null);
    }

    /**
     * 根据冷库id查询出入库信息
     * @param id
     * @return
     */
    @Override
    public List<RefrigeratoryAccessInfo> getRefrigeratoryAccessInfo(String id) {
        QueryWrapper<RefrigeratoryAccessInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("refrigeratory_id", id);
        return refrigeratoryAccessInfoMapper.selectList(wrapper);
    }

    /**
     * 根据冷库id分页查询出入库信息
     * @param refrigeratory_id
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<RefrigeratoryAccessInfo> getPageRefrigeratoryAccessInfoByrefrigeratoryId(String refrigeratory_id, Integer page, Integer size) {
        QueryWrapper<RefrigeratoryAccessInfo> wrapper = new QueryWrapper<>();
        Page<RefrigeratoryAccessInfo> infoPage = new Page<>(page, size);
        wrapper.eq("refrigeratory_id", refrigeratory_id);
        refrigeratoryAccessInfoMapper.selectPage(infoPage, wrapper);
        return infoPage;
    }

    /**
     * 分页获取所有的出入库信息
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<RefrigeratoryAccessInfo> getAllRefrigeratoryAccessInfoByrefrigeratoryId(Integer page, Integer size) {
        Page<RefrigeratoryAccessInfo> infoPage = new Page<>(page, size);
        refrigeratoryAccessInfoMapper.selectPage(infoPage, null);
        return infoPage;
    }
}
